<template>
	<view class="question">
		<scroll-view class="content" scroll-y="true">
			<view class="item" :class="{reverse:item.role=='user'}" v-for="(item,index) in historys">
				<uni-icons style="border: 0;" :type="item.rols=='user'?'qq':'help'" color="orange" size="25"></uni-icons>
				<text>{{item.content}}</text>
			</view>
		</scroll-view>
		<view class="botton">
			<uni-easyinput class="input" v-model="word" placeholder="请输入提问内容" />
						<view  class="btn" @tap="question">提问</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue'
	import {
		CONFIG
	} from "../../utils/config"
	
	let model = ref({
		"model":"moonshot-v1-8k",
		"messages":[],
		"temperature":0.3
	})
	
	let historys=ref([])
	let word=ref("")
	
	 async function question()
	{
		historys.value.push({
			"role":"user",
			"content":word.value
		})
		model.value.messages = historys.value
		let res = await uni.$post(CONFIG.kimi_url, model.value)
		historys.value.push(res.data.choices[0].message)
		console.log(res.data.choices[0].message)
		word.value=""
	}
	// question()
</script>

<style scoped lang="scss">
	.question{
		position: relative;
		height: calc(100vh - 97px);
		.content{
			height: calc(100vh - 140px);
			.item{
				display: flex;
				padding: 5px;
				text{
					border: 1px solid #ccc;
					border-radius: 5px;
					padding: 3px;
					
				}
			}
			.reverse{
				flex-direction: row-reverse;
			}
		}
			.botton{
				padding: 3rpx 5rpx;
				border: 1px solid red;
				width: 750rpx;
				display: flex;
				position: absolute;
				bottom: 0;
				button{
					margin-right: 5px;
				}
			}
	}

</style>
